package com.situ.day7;

import org.junit.Test;

public class Demo {

    @Test
    public void test1() {
        Student student = new Student(1, "zhangsan", 23, "Java2023");
        //com.situ.day7.Student@d7b1517
        //Student{id=1, name='zhangsan', age=23, className='Java2023'}
        System.out.println(student);
        //如果子类重写了这个方法，那么调用的就是子类里面重写的方法，
        //如果子类没有重写，那么调用的是从父类继承
        student.show();
    }

    @Test
    public void test2() {
        Student student = new Student(1, "zhangsan", 23, "Java2023");
        //多态表现形式：声明成父类类型，new子列对象
        //多态：根据你指向对象不同，表现出多种形态
        //学生是人
        //Student stu = new Person();
        Person person = new Student(1, "zhangsan", 23, "Java2023");
        //如果子类重写了这个方法，那么调用的就是子类里面重写的方法，
        //如果子类没有重写，那么调用的是从父类继承
        person.show();

        //老师也是人
        person = new Teacher(1, "lisi", 34, 23232);
        person.show();
    }

    @Test
    public void test4() {
        Person student = new Student(1, "zhangsan", 23, "Java2023");
        print(student);
        Person teacher = new Teacher(1, "lisi", 34, 23232);
        print(teacher);
    }

    public void print(Person person) {
        person.show();
    }

    /*public void print(Student student) {
        student.show();
    }

    public void print(Teacher teacher) {
        teacher.show();
    }*/
}
